home *** CD-ROM | disk | FTP | other *** search
- /* Like the MPW 3.0 Tool to OrphanFiles, this strips 'unit' resources */
- /* This might work on 2.0.2 -- I haven't tried -- I don't see why it wouldn't */
-
-
- /* MPW C: (3.0 or later) */
-
- #include <stdio.h>
- #include <string.h>
- #include <resources.h>
- #include <cursorctl.h>
-
- main(int argc, char *argv[])
- {
- char i, j, k;
- short resid, oldres;
- Boolean progress;
- Handle tempHandle;
-
- if (argc < 2) {
- fprintf(stderr, "## StripUnits [-p] file [files]\n");
- return 1;
- }
- InitCursorCtl(nil);
-
- for (i = 1; i < argc; i++) {
- SpinCursor(1);
- if (!strcmp(argv[i], "-p")) {
- progress = true;
- for (j = i + 1; j < argc; j++)
- argv[j - 1] = argv[j];
- argc--;
- break;
- } else
- progress = false;
- }
- if (progress) {
- printf("\StripUnits -- Very Fast Tool to replace Very Slow Script\n");
- printf("February 3, 1990 by [Go For It]\n\n");
- }
- SetResLoad(false);
- oldres = CurResFile();
- for (i = 1; i < argc; i++) {
- SpinCursor(1);
- resid = openresfile(argv[i]);
- if (ResError()) {
- fprintf(stderr, "# File %s not found\n", argv[i]);
- break;
- }
- if (j = CountResources('unit')) {
- for (k = j; k >= 1; k--) { /* Have to count backwards or we lose half of them */
- tempHandle = GetIndResource('unit', k);
- if (ResError() && progress)
- printf("# Could not access 'unit' resource index %d (error :%d) in file: %s\n"
- ,k, ResError(), argv[i]);
- RmveResource(tempHandle);
- if (progress) {
- if (ResError())
- printf("# Could not remove 'unit' resource index %d (error :%d) in file: %s\n"
- ,k, ResError(), argv[i]);
- else
- printf("# Removed 'unit' resource index %d in file: %s\n", k, argv[i]);
- }
- }
- } else if (progress)
- printf("# %s has no 'unit' resource\n", argv[i]);
-
- CloseResFile(resid);
- }
- UseResFile(oldres);
- }
-